/*
 * Copyright (C), 2013-2017, 汇通达网络有限公司
 * FileName: JobExecutorImpl.java
 * Author:   杨振宁
 * Date:     2017-4-6 下午5:04:58
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.htd.apm.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Service("jobClientExecutor")
public class JobExecutorImpl implements JobExecutor {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(JobExecutorImpl.class);
	

	@Autowired
	private ThreadPoolTaskExecutor htdFinanceJobExecutor;

	/* (non-Javadoc)
	 * @see com.htd.finance.framework.job.core.JobExecutor#executor(java.lang.Object, java.lang.reflect.Method)
	 */
	public void executor(final Object object, final Method method) {
		Thread.currentThread().setName(JobConstans.THREAD_NAME);
		try {
			htdFinanceJobExecutor.execute(new Runnable() {
				
				public void run() {
					try {
						method.invoke(object);
					} catch (IllegalAccessException e) {
						LOGGER.error("job客户端动态执行出错",e);
					} catch (IllegalArgumentException e) {
						LOGGER.error("job客户端动态执行出错",e);
					} catch (InvocationTargetException e) {
						LOGGER.error("job客户端动态执行出错",e);
					}
				}
			});
		} catch (Exception e) {
			LOGGER.error("job客户端执行job环节出错",e);
		}

	}

}
